package com.netintech.project.monitor.service.impl;

import java.util.Arrays;
import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.ImmutableMap;
import com.netintech.project.monitor.domain.dto.SysOperLogDto;
import com.netintech.project.monitor.domain.vo.SysOperLogPageVo;
import com.netintech.project.monitor.domain.vo.SysOperLogVo;
import com.netintech.project.monitor.service.SysOperLogService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.netintech.project.monitor.domain.SysOperLog;
import com.netintech.project.monitor.mapper.SysOperLogMapper;

/**
 * 操作日志 服务层处理
 *
 * @author admin
 */
@Service
public class SysOperLogServiceImpl implements SysOperLogService {
    @Autowired
    private SysOperLogMapper operLogMapper;

    /**
     * 新增操作日志
     *
     * @param operLog 操作日志对象
     */
    @Override
    public void insertOperlog(SysOperLog operLog) {
        operLogMapper.insertOperlog(operLog);
    }

    /**
     * 查询系统操作日志集合
     *
     * @param operLog 操作日志对象
     * @return 操作日志集合
     */
    @Override
    public List<SysOperLog> selectOperLogList(SysOperLog operLog) {
        return operLogMapper.selectOperLogList(operLog);
    }

    /**
     * 批量删除系统操作日志
     *
     * @param operIds 需要删除的操作日志ID
     * @return 结果
     */
    @Override
    public int deleteOperLogByIds(Long[] operIds) {
        return operLogMapper.deleteOperLogByIds(operIds);
    }

    /**
     * 查询操作日志详细
     *
     * @param operId 操作ID
     * @return 操作日志对象
     */
    @Override
    public SysOperLog selectOperLogById(Long operId) {
        return operLogMapper.selectOperLogById(operId);
    }

    /**
     * 清空操作日志
     */
    @Override
    public void cleanOperLog() {
        operLogMapper.cleanOperLog();
    }

    @Override
    public SysOperLogPageVo queryOperLogPage(SysOperLogDto operLogDto) {
        PageHelper.startPage(operLogDto.getPageNum(), operLogDto.getPageSize());
        List<SysOperLogVo> sysOperLogVos = operLogMapper.selectOperLogListVo(operLogDto);
        return SysOperLogPageVo.builder()
                .pageInfo(new PageInfo<>(sysOperLogVos, operLogDto.getPageSize()))
                .businessTypeAll(
                        Arrays.asList(
//                                1 = 新增, 2 = 修改, 3 = 删除, 4 = 授权, 5 = 导出, 6 = 导入, 7 = 强退, 8 = 生成代码, 9 = 清空数据
                                ImmutableMap.builder().put("name", "新增").put("value", 1).build(),
                                ImmutableMap.builder().put("name", "修改").put("value", 2).build(),
                                ImmutableMap.builder().put("name", "删除").put("value", 3).build(),
//                                ImmutableMap.builder().put("name", "授权").put("value", 4).build()
                                ImmutableMap.builder().put("name", "导出").put("value", 5).build(),
                                ImmutableMap.builder().put("name", "导入").put("value", 6).build(),
                                ImmutableMap.builder().put("name", "强退").put("value", 7).build(),
//                                ImmutableMap.builder().put("name", "生成代码").put("value", 8).build(),
                                ImmutableMap.builder().put("name", "清空数据").put("value", 9).build()
                        )
                )
                .statusAll(
                        Arrays.asList(
                                ImmutableMap.builder().put("name", "成功").put("value", 0).build(),
                                ImmutableMap.builder().put("name", "失败").put("value", 1).build()
                        )
                )
                .build();
    }

    @Override
    public int deleteOperLogById(Long id) {
        return operLogMapper.deleteOperLogById(id);
    }
}
